package com.ljkj.blockpay.presenter;

import android.content.Context;

import androidx.annotation.NonNull;

import com.kongzue.baseokhttp.HttpRequest;
import com.kongzue.baseokhttp.listener.JsonResponseListener;
import com.kongzue.baseokhttp.util.JsonMap;
import com.kongzue.baseokhttp.util.Parameter;
import com.ljkj.blockpay.basedata.BasePresenterImpl;
import com.ljkj.blockpay.basedata.BaseView;
import com.ljkj.blockpay.network.ApiToCConfig;
import com.ljkj.blockpay.presenter.inter.TransferInter;
import com.ljkj.blockpay.widget.LoadingDialog;
import com.luck.picture.lib.tools.ToastUtils;

/**
 * Created by yp on 2022/3/1
 */
public class TransferPresenter extends BasePresenterImpl<TransferInter.TransferInterView> implements TransferInter.TransferInterPresenter {

//    private LoadingDialog loadingDialog;
//    public void showLoading() {
//        if (loadingDialog == null) {
//            loadingDialog = new LoadingDialog.Builder(getContext()).create();
//        }
//        loadingDialog.show();
//    }
//
//    public void dismisLoading() {
//        if (loadingDialog != null) {
//            loadingDialog.dismiss();
//        }
//    }
    public TransferPresenter(@NonNull Context context, @NonNull TransferInter.TransferInterView view) {
        super(context, view);
    }


    @Override
    public void searchUserinfo(String account) {
//        showLoading();
        HttpRequest.POST(getContext(), ApiToCConfig.URL_SEARCH_USERINFO, new Parameter()
                .add("account",account)
                , new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                JsonMap jsonMap = main.getJsonMap("data");
                if (main.getInt("code") == 0 ){

                getView().SearchInfoSuccess(jsonMap);
//                dismisLoading();
                } else if (main.getInt("code") == 1006){
//                    dismisLoading();
                    ToastUtils.s(getContext(), error.getMessage());
                } else {
//                    dismisLoading();
                    ToastUtils.s(getContext(), jsonMap.getString("msg"));
                }

            }
        });
    }
}
